package com.gonsin.gview.model.form;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.gonsin.gview.model.GFormItemModel;
import com.gonsin.gview.model.data.GListDataModel;
import com.gonsin.gview.model.data.GSimpleListDataModel;
import com.gonsin.i18n.logic.T;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@ApiModel("文本输入框的描述")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class GTextInputModel extends GFormItemModel {

    @ApiModelProperty("text_input表示文本框，还有check_box\\file\\radio\\rich_text\\text_input\\tree_check_box\\tree_selector")
    private String itemType = "text_input";

    @ApiModelProperty("是否必选")
    private boolean required;

    @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
    private String keyName;

    @ApiModelProperty("显示的名字")
    private String name;

    @ApiModelProperty("输入框内提示的文本")
    private String placeholder;

    @ApiModelProperty("输入的类型 有text/number/password/re_password/text_pull")
    private String inputType;

    @ApiModelProperty("文本内容校验的正则表达式")
    private String regular;

    @ApiModelProperty("校验不通过时提示的文本")
    private String regularMessage;

    @ApiModelProperty("动态显示的js脚本，用于控制特定情况下该输入框的隐藏和显示")
    private String showIf;

    @ApiModelProperty("根据情况禁用")
    private String disableIf;

    @ApiModelProperty("文本框支持模糊搜索时，下拉的数据源")
    private GSimpleListDataModel simpleListData;

    @ApiModelProperty("当单个表单项被修改时，触发对应的action事件")
    private String buttonId;

    @Override
    public GFormItemModel tClone() {
        GTextInputModel model = new GTextInputModel();
        BeanUtil.copyProperties(this, model, CopyOptions.create().setIgnoreNullValue(true));
        if(name != null){
            model.setName(T.t(name));
        }
        if(placeholder != null){
            model.setPlaceholder(T.t(placeholder));
        }
        return model;
    }
}
